package com.rbcs.budget.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.rbcs.base.model.Item;
import com.systop.core.model.BaseModel;

/**
 * 部门预算明细表,关联预算科目,是部门预算的组成部分
 * 
 * @author Nice
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "budget_items")
public class BudgetItem extends BaseModel {

	private Integer id;

	private Double amount;

	/** 预算科目 */
	private Item item;

	/** 对应的部门预算 */
	private Budget budget;

	private List<BudgetItemMonth> bims = new ArrayList<BudgetItemMonth>(0);

	@Id
	@GeneratedValue(generator = "hibseq")
	@GenericGenerator(name = "hibseq", strategy = "hilo")
	@Column(name = "id", nullable = false)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	// 财务科目
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "item_id")
	public Item getItem() {
		return item;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "budget_id")
	public Budget getBudget() {
		return budget;
	}

	public void setBudget(Budget budget) {
		this.budget = budget;
	}
	
	@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "budgetItem")
	@OrderBy("month")
	public List<BudgetItemMonth> getBims() {
		return bims;
	}

	public void setBims(List<BudgetItemMonth> bims) {
		this.bims = bims;
	}

}
